package com.xoa.controller.dingdingManage;

import com.xoa.model.department.Department;
import com.xoa.model.dingdingManage.DingdingUpdateDept;
import com.xoa.service.dingdingManage.DingdingManageService;
import com.xoa.util.ToJson;
import com.xoa.util.common.wrapper.BaseWrapper;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

/**
 * Created by 张雨 on 2018/1/30.
 * 钉钉企业号
 */
@Controller
@RequestMapping("/dingdingManage")
public class DingdingManageController {

    @Autowired
    DingdingManageService dingdingManageService;

    //设置钉钉基础参数
    @ResponseBody
    @RequestMapping("/baseDingDingSetting")
    public BaseWrapper baseDingDingSetting(String oaUrl, String appKey, String appSecret,String corpId,String agentId) {
        return dingdingManageService.baseDingDingSetting(oaUrl, appKey, appSecret,corpId,agentId);
    }

    //获取钉钉基础参数
    @ResponseBody
    @RequestMapping("/baseDingDingGet")
    public BaseWrapper baseDingDingGet() {
        return dingdingManageService.baseDingDingGet();
    }

    //钉钉连接测试
    @ResponseBody
    @RequestMapping("/dingdingConnect")
    public BaseWrapper dingdingConnect() {
        return dingdingManageService.dingdingConnect();
    }

    //获取oa部门列表
    @ResponseBody
    @RequestMapping("/dingdingGetDeptList")
    public BaseWrapper dingdingGetDeptList(Integer deptId) {
        return dingdingManageService.dingdingGetDeptList(deptId);
    }

    //获取部门用户列表
    @ResponseBody
    @RequestMapping("/dingdingGetUserList")
    public ToJson<Department> dingdingGetUserList(Integer deptId) {
        return dingdingManageService.dingdingGetUserList(deptId);
    }

    //钉钉组织结构同步
    @ResponseBody
    @RequestMapping("/dingdingDeptSynchro")
    public BaseWrapper dingdingDeptSynchro() throws JSONException {
        return dingdingManageService.dingdingDeptSynchro();
    }

    //钉钉用户管理同步
    @ResponseBody
    @RequestMapping("/dingdingUserSynchro")
    public BaseWrapper dingdingUserSynchro(String synchroUsers) throws JSONException {
        return dingdingManageService.dingdingUserSynchro(synchroUsers);
    }

    //获取钉钉人员列表
    @ResponseBody
    @RequestMapping("/getDingdingUserList")
    public BaseWrapper getDingdingUserList() throws JSONException {
        return dingdingManageService.getDingdingUserList();
    }

    //钉钉账号与OA账号绑定与解除绑定，type为0：绑定，type为1：解除绑定（废弃）
    @ResponseBody
    @RequestMapping("/bindDingdingAndOA")
    public BaseWrapper bindDingdingAndOA(String dingdingId, String uid, Integer type) {
        return dingdingManageService.bindDingdingAndOA(dingdingId, uid, type);
    }

    //获取钉钉应用
    @ResponseBody
    @RequestMapping("/getDingdingApp")
    public BaseWrapper getDingdingApp(String appName) {
        return dingdingManageService.getDingdingApp(appName);
    }

    //钉钉应用设置
    @ResponseBody
    @RequestMapping("/dingdingAppSetting")
    public BaseWrapper dingdingAppSetting(String appName, String appId) {
        return dingdingManageService.dingdingAppSetting(appName, appId);
    }

    //钉钉组织架构管理获取部门列表
    @ResponseBody
    @RequestMapping("/dingdingDepSettingGet")
    public void dingdingDepSettingGet(HttpServletResponse response, Integer deptId) {
        dingdingManageService.dingdingDepSettingGet(response, deptId);
    }

    //钉钉组织架构管理编辑部门
    @ResponseBody
    @RequestMapping("/dingdingDepSettingEdit")
    public BaseWrapper dingdingDepSettingEdit(DingdingUpdateDept dingdingUpdateDept) {
        return dingdingManageService.dingdingDepSettingEdit(dingdingUpdateDept);
    }

    //钉钉组织架构管理删除部门
    @ResponseBody
    @RequestMapping("/dingdingDepSettingDelete")
    public BaseWrapper dingdingDepSettingDelete(Integer deptId) {
        return dingdingManageService.dingdingDepSettingDelete(deptId);
    }

    //钉钉组织架构管理获取编辑页面下拉菜单
    @ResponseBody
    @RequestMapping("/dingdingDepSettingMenu")
    public BaseWrapper dingdingDepSettingMenu() {
        return dingdingManageService.dingdingDepSettingMenu();
    }

    //朱洪飞

    //钉钉企业号设置
    @RequestMapping("/getEnterpriseManage")
    public String getEnterpriseManage() {
        return "/app/dingdingManage/enterpriseSetting";
    }
    //企业号设置
    @RequestMapping("/getIndex")
    public String getIndex() {
        return "/app/dingdingManage/index";
    }
    //基础参数设置
    @RequestMapping("/getArameterSetting")
    public String getArameterSetting() {
        return "/app/dingdingManage/arameterSetting";
    }
    //同步部门
    @RequestMapping("/getDataImport")
    public String getDataImport() {
        return "/app/dingdingManage/dataImport";
    }
    //数据导入 - 组织架构初始化
    @RequestMapping("/getChooseDepartment")
    public String getChooseDepartment() {
        return "/app/dingdingManage/chooseDepartment";
    }
    //数据导入 - 人员和日志
    @RequestMapping("/getImportPersonnel")
    public String getImportPersonnel() {
        return "/app/dingdingManage/importPersonnel";
    }
    //数据导入 - 人员
    @RequestMapping("/getImportPeople")
    public String getImportPeople() {
        return "/app/dingdingManage/importPeople";
    }
    //公告通知
    @RequestMapping("/getPublicNotice")
    public String getPublicNotice() {
        return "/app/dingdingManage/publicNotice";
    }
    //导入日志
    @RequestMapping("/getImportLogs")
    public String getImportLogs() {
        return "/app/dingdingManage/importLogs";
    }
    //钉钉组织架构管理
    @RequestMapping("/getOrganizationManagement")
    public String getOrganizationManagement() {
        return "/app/dingdingManage/organizationManagement";
    }
    //OA用户绑定
    @RequestMapping("/getOaBinding")
    public String getOaBinding() {
        return "/app/dingdingManage/oaBinding";
    }
    //组织架构管理
    @RequestMapping("/getOrganizationalStructure")
    public String organizationalStructure() {
        return "/app/dingdingManage/organizationalStructure";
    }

}
